<%@ page language="java" isELIgnored="false"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>栏目管理</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link href="/admin/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" />
<link href="/admin/public/animate.css" rel="stylesheet" />
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" type="text/css"
	href="${request.getContext }/admin/css/xcConfirm.css" />
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
<title>信息管理系统</title>
</head>

<body>
	<div id="wrapper" class="container">
		<!--标编辑-->
		<div id="biaobj" class=" wrapper wrapper-content animated fadeInRight">
			<h3>管理员角色权限</h3>
			<div class="right_box" id="right_box">
				<!--表格部分-->
				<div class="ibox-content">
					<div class="row">
						<div class="col-sm-12">
							<form action="">
								<input type="hidden" value="${roleId }" id="roleId" />
								<c:forEach items="${li }" var="li">
									<input type="hidden" value="${li.AuthorityID }"
										class="AuthorityID" />
								</c:forEach>
								<table
									class="table table-striped table-bordered table-hover dataTables-example">
									<thead>
										<tr>
											<th width="100px" style="text-align: right;">模块</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody>
										<c:forEach items="${settings }" var="sett">
											<tr>
												<td class="text-right w-150px">${sett.key }<input
													type="checkbox" name="allchecker" value="${sett.key }"></td>
												<td id="group1" class="pv-10px" style="text-align: left">
													<c:forEach items="${sett.value }" var="val">
														<input type="checkbox" name="actions-1" value="${val }"
															data-role="${sett.key }" />
														<span class="priv">${val }</span>
													</c:forEach>
												</td>
											</tr>
										</c:forEach>
									</tbody>
								</table>
								<input type="button"
									style="width: 82px; height: 34px; margin-left: 12px"
									onclick="addRoleAuthority();" value="保存"
									class="col-lg-3 btn btn-success" />
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="/admin/public/jquery-1.11.3.js"></script>
	<script src="/admin/public/bootstrap.min.js" type="text/javascript"></script>
	<script src="${request.getContext }/admin/js/xcConfirm.js"
		type="text/javascript" charset="utf-8"></script>
	<script>
		$(function() {
			window.onload = function() {
				var AuthorityArr = $(".AuthorityID");
				if (AuthorityArr.length > 0) {
					for (var i = 0; i < AuthorityArr.length; i++) {
						$("input[type=checkbox][name='actions-1']").each(
								function(index, item) {
									if ($(this).val() == $(AuthorityArr[i])
											.val()) {
										$(this).attr("checked", true);
									}
								});

					}
				}
			};
		});
		function addRoleAuthority() {
			var spCodesTemp = "";
			var spCodesTemp2 = "";
			$('input:checkbox[name=actions-1]:checked').each(function(i) {
				spCodesTemp2 = $(this).data("role");
				if (0 == i) {
					spCodesTemp = spCodesTemp2 + "-" + $(this).val();
				} else {
					spCodesTemp += ("," + spCodesTemp2 + "-" + $(this).val());
				}
			});
			var roleId = $("#roleId").val();
			$.ajax({
				type : "post",
				url : "/admin/role/saveRoleAuthority",
				data : {
					"roleId" : roleId,
					"spCodesTemp" : spCodesTemp
				},
				dataType : "json",
				success : function(data) {
					window.wxc.xcConfirm(data.msg,
							window.wxc.xcConfirm.typeEnum.info, {
								onOk : function() {
									location.reload();
								}
							})

				},
				error : function() {
					alert("系统异常，请联系管理员！");
				}
			});
		}
	</script>
</body>

</html>